//
//  LWZ_MusicVCY.m
//  MusicFM
//
//  Created by 李光耀 on 16/1/7.
//  Copyright © 2016年 LGY. All rights reserved.
//

#import "LWZ_MusicVCY.h"
#import "LWZ_MusicFirstTableViewCellY.h"
#import "LWZ_MusicMoreMoreViewController.h"

@interface LWZ_MusicVCY ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSDictionary *dic_Music;
@property (nonatomic, strong)NSDictionary *dic_Hot;
@property (nonatomic, strong)NSDictionary *dic_KTV;
@property (nonatomic, strong)NSDictionary *dic_OnLine;
@property (nonatomic, strong)NSDictionary *dic_TV;
@property (nonatomic, strong)NSDictionary *dic_Mine;
@property (nonatomic, strong)NSMutableArray *mutablearray;

@end



@implementation LWZ_MusicVCY





- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"通知" message:@"你是傻逼吗!" delegate:self cancelButtonTitle:@"我是傻逼" otherButtonTitles:nil, nil];
//        alertView.alertViewStyle = UIAlertViewStyleDefault;
//        [alertView show];
//        alertView.cancelButtonIndex = 1;

    self.mutablearray = [[NSMutableArray alloc]init];
    self.navigationItem.title = @"先看你耀哥哥的";
    
    [self creatTable];
   [self getURl];
 
    
    
}
- (void)creatTable{
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
#warning xib 注册重用池方法
    [self.tableView registerNib:[UINib nibWithNibName:@"LWZ_MusicFirstTableViewCellY"bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"LWZ_MusicFirstTableViewCellYIdentifier"];
    
    //添加添加阴影效果
    self.tableView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    
    self.tableView.layer.shadowOffset = CGSizeMake(-8, 8);
    
    self.tableView.layer.shadowOpacity = 1;
    
    self.tableView.clipsToBounds = false;
    self.tableView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
    
    
    
    [self.view addSubview:self.tableView];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LWZ_MusicFirstTableViewCellY *cell = [tableView dequeueReusableCellWithIdentifier:@"LWZ_MusicFirstTableViewCellYIdentifier"];
    if (self.mutablearray.count >= 5) {
        cell.dic = self.mutablearray[indexPath.row];
    }
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 212;
}

- (void)getURl{
    [MHNetWorkTask getWithURL:kMusicPage_Music withParameter:nil withHttpHeader:nil withResponseType:ResponseTypeJSON withSuccess:^(id result) {
        self.dic_Music = [NSDictionary dictionaryWithDictionary:result];
        [self.mutablearray addObject:_dic_Music];
        NSLog(@"1");
        if (self.mutablearray.count == 6) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self.tableView reloadData];
                
            });
        }

    } withFail:^(NSError *error) {
        
    }];
    [MHNetWorkTask getWithURL:kMusicPage_Hot withParameter:nil withHttpHeader:nil withResponseType:ResponseTypeJSON withSuccess:^(id result) {
        self.dic_Hot = [NSDictionary dictionaryWithDictionary:result];
        [self.mutablearray addObject:_dic_Hot];
        NSLog(@"2");
        if (self.mutablearray.count == 6) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self.tableView reloadData];
                
            });
        }
    } withFail:^(NSError *error) {
        
    }];
    [MHNetWorkTask getWithURL:kMusicPage_KTV withParameter:nil withHttpHeader:nil withResponseType:ResponseTypeJSON withSuccess:^(id result) {
        self.dic_KTV = [NSDictionary dictionaryWithDictionary:result];
        [self.mutablearray addObject:_dic_KTV];
        NSLog(@"3");
        if (self.mutablearray.count == 6) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self.tableView reloadData];
                
            });
        }
    } withFail:^(NSError *error) {
        
    }];
    [MHNetWorkTask getWithURL:kMusicPage_OnLine withParameter:nil withHttpHeader:nil withResponseType:ResponseTypeJSON withSuccess:^(id result) {
        self.dic_OnLine = [NSDictionary dictionaryWithDictionary:result];
        [self.mutablearray addObject:_dic_OnLine];
        NSLog(@"4");
        if (self.mutablearray.count == 6) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self.tableView reloadData];
                
            });
        }
    } withFail:^(NSError *error) {
        
    }];
    [MHNetWorkTask getWithURL:kMusicPage_TV withParameter:nil withHttpHeader:nil withResponseType:ResponseTypeJSON withSuccess:^(id result) {
        self.dic_TV = [NSDictionary dictionaryWithDictionary:result];
        [self.mutablearray addObject:_dic_TV];
        NSLog(@"5");
        if (self.mutablearray.count == 6) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self.tableView reloadData];
                
            });
        }
    } withFail:^(NSError *error) {
        
    }];
    [MHNetWorkTask getWithURL:kMusicPage_Mine withParameter:nil withHttpHeader:nil withResponseType:ResponseTypeJSON withSuccess:^(id result) {
        self.dic_Mine = [NSDictionary dictionaryWithDictionary:result];
        [self.mutablearray addObject:_dic_Mine];
        NSLog(@"6");
        if (self.mutablearray.count == 6) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self.tableView reloadData];
                
            });
        }

    } withFail:^(NSError *error) {
        
    }];


    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    LWZ_MusicMoreMoreViewController *more = [[LWZ_MusicMoreMoreViewController alloc]init];
    more.arraySource = self.mutablearray[indexPath.row][@"songs"];
    [self.navigationController pushViewController:more animated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
